package com.sangeng.controller;

import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.dto.AddRoleDto;
import com.sangeng.domain.dto.ChangeRoleDto;
import com.sangeng.domain.dto.UpdateRoleDto;
import com.sangeng.domain.vo.PageVo;
import com.sangeng.service.RoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("system/role")
@RequiredArgsConstructor
public class RoleController {
    private final RoleService roleService;

    /**
     * 需要有角色列表分页查询的功能。
     * 要求能够针对角色名称进行模糊查询。
     * 要求能够针对状态进行查询
     * 要求按照role_sort进行升序排列。
     * */
    @GetMapping("/list")
    public ResponseResult<PageVo> getRoleList(Integer pageNum, Integer pageSize, String roleName, String status) {
        return roleService.getRoleList(pageNum, pageSize, roleName, status);
    }

    /**
     * 改变角色状态
     * */
    @PutMapping("/changeStatus")
    public ResponseResult<String> changeRoleStatus(@RequestBody ChangeRoleDto role){
        return roleService.changeRoleStatus(role);
    }

    /**
     *
     * */
    @PutMapping
    public ResponseResult<String> updateRole(@RequestBody UpdateRoleDto roleDto) {
        return roleService.updateRole(roleDto);
    }
    
    @PostMapping
    public ResponseResult<String> addRole(@RequestBody @Validated AddRoleDto roleDto) {
        return roleService.addRole(roleDto);
    }

    @DeleteMapping("/{idList}")
    public ResponseResult<String> deleteRole(@PathVariable List<Long> idList) {
        return roleService.deleteRoleById(idList);
    }
    
}
